// 示例方法，没有实际意义
import moment from "moment";
export function trim(str: string) {
  return str.trim();
}

export function handleInputChange(e: any) {
  const inputValue = e.target.value;
  return inputValue.trim();
}

// 格式label,value
export function formatDict(data: Array<any>, label: string, value: string) {
  return data.map((item) => ({
    label: item[label],
    value: item[value],
  }));
}

export function formatClass(
  data: [],
  key: string,
  name: string,
  value: string
) {
  let arr = [];
  for (let i = 0; i < data.length; i++) {
    let temp = {
      label: data[i][key] + "-" + data[i][name],
      value: data[i][value],
    };
    arr.push(temp);
  }
  return arr;
}

export function filterColor(data: [], value: string) {
  let arr = [];
  for (let i = 0; i < data.length; i++) {
    arr.push(data[i][value]);
  }
  return arr;
}

export function formatRangeTime(time: any, format = "YYYY-MM-DD") {
  if (time.length) {
    const [start, end] = time;
    return {
      startTime: moment(start).format(format),
      endTime: moment(end).format(format),
    };
  }
  console.error("入参不正确");
  return [];
}
